import { getChannelListAPI } from "@/apis/list";
import { ChannelItem } from "@/types/list";
import { useEffect, useState } from "react";

// 获取tabs(频道列表)数据的自定义hook函数
export const useTabs = () => {
  const [channelList, setChannelList] = useState<ChannelItem[]>([]);
  // 获取频道列表的方法
  const getChannelList = async () => {
    const res = await getChannelListAPI();
    setChannelList(res.data.channels);
  };
  // useEffect(生命周期函数也会执行且先于组件的生命周期函数执行)
  useEffect(() => {
    getChannelList();
  }, []);
  // 暴露数据/方法
  return {
    channelList,
  };
};
